import React ,{ Component } from 'react';

import {connect} from 'react-redux';

import { actions } from './_index.js';

class View extends Component{
    constructor(props){
        super(props);
        this.state = {
            ajaxCfg:{
                url:'/home/mediareports',
                cfg:{
                    page_number:'1',
                    page_size:'10',
                },
                headers:{

                }
            }
        }
    }
    getPddList(){
        const { getPddFn } = this.props;
        const { ajaxCfg } = this.state;
        getPddFn('自动获取',ajaxCfg);
    }
    componentDidMount(){
        this.getPddList();
    }
    lists(){
        const { pddData } = this.props;
        return pddData.pageData.data.map((val,index)=>{
            return(
                <li key={val.id}>{val.main_title}</li>
            )
        })
    }
    render(){
        const { pddData } = this.props;

        return(
            <React.Fragment>
                <div>ajax page</div>
                {
                    pddData.pageData
                    ?
                    <ul>{this.lists()}</ul>
                    :
                    ''
                }
            </React.Fragment>
        )
    }
}
const mapStateToProps = (state)=> {
  return {
      pddData:state.ajaxPage
  }
}
const mapDispatchToProps = (dispatch, ownProps) => {
	return {
		getPddFn: (text,ajaxCfg) => dispatch(actions.getFn(text,ajaxCfg,dispatch))
	}
};

export default connect(mapStateToProps,mapDispatchToProps)(View);
